<template>
	<view>
		<u-popup :show="show" @close="close" @open="open" round="20rpx" :zIndex='10078' overlayStyle='z-index:10075;'>
			<view class="popbox">
				<view class="popbox__title">
					<image src="/static/home/sz.png" class="popbox__title__icon" mode=""></image>
					需完善用户资料后方可操作
				</view>
				<image src="/static/home/wsicon.png" class="popbox__pic" mode=""></image>
				<u-button color="#07C160" text="点我完善" @getphonenumber='getphonenumber'
					open-type="getPhoneNumber"></u-button>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	export default {
		name: "wanshan",
		data() {
			return {
				show: false,
				p: {
					type: "loading",
					title: "正在绑定",
					message: "正在加载",
					iconUrl: "https://uviewui.com/demo/toast/loading.png",
					url: "/pages/my/wanshan",
				},
			};
		},
		methods: {
			open() {
				this.show = true
			},
			close() {
				this.show = false
			},
			getphonenumber(e) {
				if (e.detail.errMsg == 'getPhoneNumber:ok') {
					let {
						encryptedData,
						iv
					} = e.detail
					let openid = uni.getStorageSync('xguserinfo').openid
					user.getWechatPhone({
						encryptedData,
						iv,
						openid
					}).then(res => {
						if (res.data.code == 1) {
							this.show=false
							// 重新获取用户信息
							user.userindex().then(res=>{
								uni.setStorageSync('xguserinfo',res.data.data.userinfo)
							})
							this.showToast(this.p)
							
						}
					})
				}

			},
			showToast(params) {
				this.$refs.uToast.show({
					...params,
					complete() {
						params.url &&
							uni.navigateTo({
								url: params.url,
							});
					},
				});
			},

		}
	}
</script>

<style lang="scss">
	.popbox {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 65rpx 112rpx;

		&__title {
			font-family: PingFang-SC, PingFang-SC;
			font-weight: 800;
			font-size: 37rpx;
			color: #313131;
			line-height: 37rpx;
			padding: 0 0 84rpx;
			display: flex;
			align-items: center;

			&__icon {
				width: 45rpx;
				height: 45rpx;
				margin-right: 13rpx;
			}
		}

		&__pic {
			width: 297rpx;
			height: 297rpx;
			margin-bottom: 75rpx;
		}
	}
</style>